package hc.j2me.util;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Image;

public class ScreenUtil {
	public static final String BACK = "Back";
	public static final String EXIT = "1011";
	public static final String INFO = "3";
	public static final String ERROR = "1";
	public static final String OK = "1010";
	public static final String CANCEL = "1018";

	public static short middleX, middleY;

	public static Image loadImage(String url) {
		HttpConnection hpc = null;
		DataInputStream dis = null;
		try {
			hpc = (HttpConnection) Connector.open(url);
			int length = (int) hpc.getLength();
			byte[] data = new byte[length];
			dis = new DataInputStream(hpc.openInputStream());
			dis.readFully(data);
			return Image.createImage(data, 0, data.length);
		} catch (Exception e) {

		} finally {
			if (hpc != null)
				try {
					hpc.close();
				} catch (IOException e) {
				}
			if (dis != null)
				try {
					dis.close();
				} catch (IOException e) {
				}
		}
		return null;
	}

}
